home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11098 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: gwen.pcug.co.uk!altheim!broldham
  2. Newsgroups: comp.lang.c
  3. Message-ID: <1247@altheim.win-uk.net>
  4. References: <1239@altheim.win-uk.net><4iklpm$28s@sparcserver.lrz-muenchen.de>
  5. Reply-To: broldham@altheim.win-uk.net (Brian R. Oldham)
  6. From: broldham@altheim.win-uk.net (Brian R. Oldham)
  7. Date: Wed, 20 Mar 1996 23:00:04 GMT
  8. Subject: Re: Pointers to register
  9.  
  10.  
  11. In article <4iklpm$28s@sparcserver.lrz-muenchen.de>, Kurt Watzka (watzka@stat.uni-muenchen.de) writes:
  12. >broldham@altheim.win-uk.net (Brian R. Oldham) writes:
  13. >
  14. >>A couple of weeks ago someone posted the opinion that all objects in
  15. >>memory must have an address, which might have gone uncontested but for
  16. >>the fact that he added that therefore all pointers must point to an
  17. >>address. Someone else reminded us that registers don't have an address.
  18. >
  19. >>Bearing in mind the usual way to assign a pointer:
  20. >
  21. >>    ptr = &var;
  22. >
  23. >>is correct for objects in memory, but how do you assign a pointer
  24. >>to a register? 
  25. >
  26. >>The following function (a getch() for x86) works: But is it right??
  27. >>    
  28. >>/* Read next keystroke */
  29. >>#include <dos.h>
  30. >
  31. >>#define KEYBD 0x16
  32. >
  33. >>static union REGS inregs, outregs;
  34. >
  35. >>void getkey(int *scancode, char *ch) 
  36. >>{
  37. >>    inregs.h.ah = 0x00;
  38. >>    int86(KEYBD,&inregs,&outregs);
  39. >
  40. >You use two structs that are members of a union to communicate with 
  41. >a function that knows how to deal with them. This does not mean that 
  42. >you are "taking the address of a register".  
  43. >
  44. >"inregs" and "outregs" are variables in your program. Try:
  45. >
  46. >   {
  47. >      union REGS foo, bar, baz, bam;
  48. >   }
  49. >
  50. >Those variables are in no way related to any registers.
  51. >Kurt
  52. >--
  53.  
  54. Yes Kurt, I think I've got the message by now. But where you guys keep
  55. missing the point (like Nottm Forest kept missing the Bayern Munich
  56. goalposts :-{ ) is that if declaration:
  57.  
  58.     *ptr = var;
  59.     
  60. is wrong for other objects in memory then why does it work for:
  61.  
  62.     *ptr = union_member;
  63.  
  64. And why does my compiler complain at the correct way:
  65.  
  66.     ptr = &union_member;
  67.  
  68.  
  69. ---
  70. Brian Oldham
  71. Hucknall UK
  72. !...Gesundbrunnen
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.